package com.yuanfengPlus.utils;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String message;
    private T data;
    private int count; // 新增计数字段
    private String token;

    // 构造方法
    public Result(int code, String message, T data, int count) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

        public Result(int code, String message, T data, String token) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.token = token;
    }

    // 成功无数据结果的静态方法
    public static <T> Result<T> success() {
        return new Result<>(200, "成功", null, 0);
    }

    // 成功结果有数据的静态方法
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data, 0);
    }

    // 成功结果有数据有计数的静态方法
    public static <T> Result<T> success(T data, int count) {
        return new Result<>(200, "成功", data, count);
    }
    public static <T> Result<T> success(T data, String message) {
        return new Result<>(200, message, data,0);
    }
    public static <T> Result<T> success(String message) {
        return new Result<>(200, message, null,0);
    }

    //写一个用户返回信息以及token的方法
    public static <T> Result<T> success( T data , String message,String token) {
        return new Result<>(200, message, data,token);
    }
    // 失败结果的静态方法
    public static <T> Result<T> failure(int code, String message) {
        return new Result<>(code, message, null, 0);
    }
}

